package com.lovegu.thread;

import java.util.concurrent.*;

/**
 * @author 老顾
 * @title: TestCallable
 * @projectName java-restudy
 * @email: 1437594522@qq.com
 * @date 2022/9/22 15:37
 */
public class TestCallable implements Callable<Boolean> {
    private String url;     //网络地址图片
    private String name;    //保存的文件名
    public TestCallable(String url,String name){
        this.url = url;
        this.name = name;
    }

    //下载图片线程的执行体
    @Override
    public Boolean call(){
//        WebDownloader2 webDownloader = new WebDownloader2();
//        webDownloader.downloader(url,name);
        System.out.println("下载了文件名为："+name);
        return true;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        TestCallable t1 = new TestCallable("http://52dm.52dmtp.com/d/file/6696feed3b88b6cfd2c14c714f03728c.jpg","wall1.jpg");
        TestCallable t2 = new TestCallable("http://52dm.52dmtp.com/d/file/88a827ade62bc239f06590acc993ae56.jpg","wall2.jpg");
        TestCallable t3 = new TestCallable("http://52dm.52dmtp.com/d/file/e93a6b31002da59e3622998a92d324dc.jpg","wall3.jpg");
        //创建执行服务
        ExecutorService ser = Executors.newFixedThreadPool(3);
        //提交执行
        Future<Boolean> result1 = ser.submit(t1);
        Future<Boolean> result2 = ser.submit(t2);
        Future<Boolean> result3 = ser.submit(t3);
        //获取结果
        boolean rs1 = result1.get();
        boolean rs2 = result2.get();
        boolean rs3 = result3.get();
        //关闭服务
        ser.shutdown();
    }
}
